package servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AddNewItemServlet extends HttpServlet 
{
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		doProcessing(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		doProcessing(req, resp);
	}
	
	private void doProcessing(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		String category = req.getParameter("category");
		String description = req.getParameter("description");
		String itemWeight = req.getParameter("itemWeight");
		String price = req.getParameter("price");
		String quantityInStock = req.getParameter("quantityInStock");
		
		req.getSession().setAttribute("category", category);
		req.getSession().setAttribute("description", description);
		req.getSession().setAttribute("itemWeight", itemWeight);
		req.getSession().setAttribute("price", price);
		req.getSession().setAttribute("quantityInStock", quantityInStock);
		
		// go back to the index.jsp
		RequestDispatcher dispatcher = req.getRequestDispatcher("stockReport.jsp");
		dispatcher.forward(req, resp);
	}
}
